<%@page import="com.myweb.DBTools"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="javax.sql.rowset.WebRowSet" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>修改购物车数据</title>
</head>
<body>
<div class="container2">
<div class="form-wrapper2">
<form action="cart.jsp" method="post">
<!-- 表单内容 -->
<%
request.setCharacterEncoding("utf-8");
String dish_id = request.getParameter("dish_id");
if(dish_id != null && !dish_id.isEmpty()) {
// 为了安全起见，对dish_id进行适当的处理，比如使用HTML转义
dish_id = java.net.URLEncoder.encode(dish_id, "UTF-8");
String sql = "SELECT * FROM shoppingcar WHERE dish_id='" + dish_id + "'";
WebRowSet rs = com.myweb.DBTools.getRS(sql);

if (rs != null && rs.next()) {
// 获取查询结果并显示在表单中
String name = rs.getString("name");
double price = rs.getDouble("price");
int amount = rs.getInt("amount");
String table_id = rs.getString("table_id");
String restaurant_id = rs.getString("restaurant_id");
// 此处添加其他需要显示的字段
%>
<input type="hidden" id="dish_id" name="dish_id" value="<%=dish_id%>">
<label for="name">餐品名称:</label>
<input type="text" id="name" name="name" value="<%=name%>" required>
<label for="price">单价:</label>
<input type="text" id="price" name="price" value="<%=price%>" required readonly>
<label for="amount">数量:</label>
<input type="number" id="amount" name="amount" value="<%=amount%>" required min="1" max="100">
<input type="hidden" id="table_id" name="table_id" value="<%=table_id%>" required>
<input type="hidden" id="restaurant_id" name="restaurant_id" value="<%=restaurant_id%>" required>
<%
} else {
// 如果没有找到记录，重定向回订单详情页面或显示错误信息
response.sendRedirect("errorPage.jsp?error=dishNotFound");
return;
}
rs.close();
} else {
// 如果没有dish_id，重定向回订单详情页面或显示错误信息
response.sendRedirect("error.jsp?error=noDishId");
return;
}
%>
<input type="hidden" name="btn" value="修改">
<input type="submit" value="提交修改">
</form>
</div>
</div>
</body>
</html>
